package com.cjlgb.design.oauth.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.cjlgb.design.upms.api.entity.Oauth2Account;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @author WFT
 * @date 2019/8/13
 * description: 基于Oauth2.0协议的账号详细信息
 */
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Oauth2AccountDetails extends Oauth2Account implements UserDetails {

    @Override
    public void setLockFlag(Integer lockFlag) {
        super.setLockFlag(lockFlag);
        this.accountNonLocked = lockFlag == 0;
    }

    /**
     * 权限列表
     */
    @TableField(exist = false)
    private Collection<? extends GrantedAuthority> authorities;

    @TableField(exist = false)
    private boolean accountNonExpired = true;

    @TableField(exist = false)
    private boolean credentialsNonExpired = true;

    @TableField(exist = false)
    private boolean enabled = true;

    @TableField(exist = false)
    private boolean accountNonLocked;

}
